package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Classinfo;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.service.IClassinfoService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.qo.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/classinfo")
public class ClassinfoController {

    @Autowired
    private IClassinfoService classinfoService;


    @RequiresPermissions(value = {"classinfo:list","班级页面"},logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<Classinfo> pageInfo = classinfoService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "classinfo/list";
    }

    @RequestMapping("/delete")
    @RequiresPermissions(value = {"classinfo:delete","班级删除"},logical = Logical.OR)
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            classinfoService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"classinfo:saveOrUpdate","班级新增/编辑"},logical = Logical.OR)
    @ResponseBody
    public JsonResult saveOrUpdate(Classinfo classinfo){
        if (classinfo.getId() != null) {
            classinfoService.update(classinfo);
        }else {
            classinfoService.save(classinfo);
        }
        return new JsonResult();
    }
}
